<template>
  <div class="box">
    <div class="message">
      <!-- 搜索 -->
      <div class="search">
        <a-input-search class="search-input" v-model:value="searchValue" placeholder="搜索" @search="onSearch" />
      </div>
      <!-- 信息列表 -->
      <div class="messege-list">
        <div class="item" v-for="item in userList" v-bind:key="item.name" :style="{ background: chooseMes == item.id ? '#ccc' : '#dfdede' }" @click="chooseHandle(item)">
          <div class="heade">
            <img :src="item.img" alt="" />
          </div>
          <div class="title">{{ item.name }}</div>
        </div>
      </div>
    </div>
    <div class="chat">
      <div class="tip">{{ chooseTitle ? chooseTitle : userList[0].name }}</div>
      <u-chat class="chat-interface"></u-chat>
    </div>
  </div>
</template>

<script>
import { ref } from '@vue/reactivity';
import UChat from './chatInterface.vue';
export default {
  setup() {
    let searchValue = ref('');
    let chooseMes = ref(1);
    let chooseTitle = ref('');
    let userList = ref([
      {
        id: 1,
        name: '群聊1',
        img: require('@/assets/head.jpg')
      },
      {
        id: 2,
        name: '群聊2',
        img: require('@/assets/head.jpg')
      },
      {
        id: 3,
        name: '群聊3',
        img: require('@/assets/head.jpg')
      }
    ]);
    const onSearch = () => {
      console.log('搜索');
    };
    const chooseHandle = (item) => {
      chooseMes.value = item.id;
      chooseTitle.value = item.name;
    };
    return {
      searchValue,
      chooseMes,
      chooseTitle,
      userList,
      onSearch,
      chooseHandle
    };
  },
  components: {
    UChat
  }
};
</script>

<style scoped lang="scss">
.text-el {
  display: -webkit-box; /*必须结合的属性,将对象作为弹性伸缩盒子模型显示*/
  -webkit-line-clamp: 1; /*设置多少行*/
  -webkit-box-orient: vertical; /*必须结合的属性,设置或检索伸缩盒对象的子元素的排列方式*/
  overflow: hidden; /*文本会被修剪，并且剩余的部分不可见*/
  text-overflow: ellipsis; /*显示省略号来代表被修剪的文本*/
}
.box {
  width: 100%;
  height: 100%;
  display: flex;
  .message {
    width: 150px;
    height: 600px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    .search {
      width: 100%;
      height: 50px;
      background: #f7f7f7;
      border-right: 2px solid #ccc;
      border-bottom: 1px solid #ccc;
      padding: 0px 5px;
      box-sizing: border-box;
      .search-input {
        border-radius: 5px;
      }
    }
    .messege-list {
      width: 100%;
      flex: 1;
      overflow-y: scroll;
      background: #dfdede;
      border-right: 2px solid #ccc;

      &::-webkit-scrollbar {
        display: none;
      }
      // f5f5f5
      .item {
        width: 100%;
        height: 50px;
        display: flex;
        font-size: 14px;
        font-weight: 600;
        box-sizing: border-box;
        padding: 5px;
        cursor: pointer;
        &:hover {
          background: #ccc;
        }
        .heade {
          width: 35px;
          height: 35px;
          img {
            width: 100%;
          }
        }
        .title {
          margin-left: 5px;
          width: 100px;
          height: 35px;
          text-align: left;
          line-height: 35px;
          @extend .text-el;
        }
      }
    }
  }
  .chat {
    flex: 1;
    flex-direction: column;
    .tip {
      width: 100%;
      height: 50px;
      text-align: left;
      box-sizing: border-box;
      line-height: 50px;
      font-size: 16px;
      padding-left: 15px;
      border-bottom: 1px solid #ccc;
    }
  }
}
</style>
